function checkexchange()
{
	var f = form("ExchangeForm");
	if (f.dest.options[f.dest.selectedIndex].value == '')
	{
		msg('错误：请选择目的积分类型！');
		f.dest.focus();
		return false;
	}
	if (f.dest.options[f.dest.selectedIndex].value == f.source.options[f.source.selectedIndex].value)
	{
		msg('错误：源积分类型和目的积分类型不能一致！');
		f.dest.focus();
		return false;
	}
	if (f.count.value == '')
	{
		msg('错误：请输入兑换数量');
		f.count.focus();
		return false;
	}
	if (isNaN(f.count.value))
	{
		msg('错误：兑换数量必须是数字');
		f.count.focus();
		return false;
	}
	
	if (parseInt(f.count.value) <= 0)
	{
		msg('错误：兑换数量必须大于0');
		f.count.focus();
		return false;
	}
	
	var fl = 0, n = 1, u = 2, r = 3, v = 4;
	var screditindex = parseInt(f.source.options[f.source.selectedIndex].value.replace('Credit', '')) -1;
	if (parseInt(f.count.value) > credits[screditindex][4])
	{
		msg('您当前只有 ' + credits[screditindex][v] + credits[screditindex][u] + credits[screditindex][n] + '，无法将更多' + credits[screditindex][n] + '兑换成其他类型的积分！');
		f.count.focus();
		return false;
	}
	
	return true;
}

function calculate()
{
	if (checkexchange())
	{
		var f = form("ExchangeForm");
		var fl = 0, n = 1, u = 2, r = 3, v = 4;
		var screditindex = parseInt(f.source.options[f.source.selectedIndex].value.replace('Credit', '')) -1;
		var dcreditindex = parseInt(f.dest.options[f.dest.selectedIndex].value.replace('Credit', '')) -1;
		
		var c = parseInt(f.count.value);
		
		var result = (c * credits[screditindex][r]) / credits[dcreditindex][r];
		if (result < 1)
		{
			msg('错误： ' + c + credits[screditindex][u] + credits[screditindex][n] + '不够兑换 1' +credits[dcreditindex][u] + credits[dcreditindex][n]);
		}
		else
		{
			msg('可将' + ((result * credits[dcreditindex][r]) / credits[screditindex][r]) + ' ' + credits[screditindex][u] + credits[screditindex][n] + ' 兑换成' + result + '' + credits[dcreditindex][u] + credits[dcreditindex][n]);
			
		}
	}
}

function onselectdest()
{
	var f = form("ExchangeForm");
	if (f.dest.options[f.dest.selectedIndex].value == '')
	{
		return false;
	} 
	calculate();
}

function msg(v)
{
	$('msg').innerHTML = v;
	$('msg').style.display = '';
}

function checkpostexchange()
{
	var f = form("ExchangeForm");
	if (f.password.value == '')
	{
		alert('请输入密登录密码');
		f.password.focus();
		return false;
	}
	return checkexchange();
}